import Clipboard from 'clipboard'
import { MessagePlugin } from 'tdesign-vue';

function clipboardSuccess() {
  MessagePlugin.success(`复制成功`);
}

function clipboardError() {
  MessagePlugin.error(`复制失败`);
}

export default function handleClipboard(text, event) {
  if(!text) return;
  const clipboard = new Clipboard(event.target, {
    text: () => text
  })
  clipboard.on('success', () => {
    clipboardSuccess()
    clipboard.destroy()
  })
  clipboard.on('error', () => {
    clipboardError()
    clipboard.destroy()
  })
  clipboard.onClick(event)
}
